package ti26;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Test {

    public static void main(String[] args) {

        Test test=new Test();
        System.out.println(test.nowTime());
        System.out.println(test.shengRi("张三", "1998-03-25"));
    }
    //获取当前时间
    public String nowTime(){
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String nowtime = simpleDateFormat.format(date);
        return nowtime;
    }

    public String shengRi(String name,String shengri){
        String text ="";
        Date date1 = new Date();
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
        String newtime = simpleDateFormat1.format(date1);
        int newyear = Integer.valueOf(newtime.substring(0,4));
        int oldyear = Integer.valueOf(shengri.substring(0,4));
        int nianLing = newyear-oldyear;
        int newRi = Integer.valueOf(newtime.substring(5,10).replace("-",""));
        int oldRi = Integer.valueOf(shengri.substring(5,10).replace("-",""));
       if (newRi-oldRi<0){
            text = name + nianLing + "岁，今年生日未过！";
       }else {
          text = name + nianLing + "岁，今年生日已过！";
       }

        return text;
    }

}
